package com.lookme.lmtool.cracker.filter.warping;

import com.jhlabs.image.CropFilter;
import com.lookme.lmtool.cracker.CrackerConstants;
import com.lookme.lmtool.cracker.annotation.FilterAnnotation;
import com.lookme.lmtool.cracker.annotation.ParamAnnotation;
import com.lookme.lmtool.cracker.filter.AbstractFilter;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;

import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;

@FilterAnnotation(groupName = CrackerConstants.FILTER_GROUP_NAME_WARPING,name="裁剪图像")
public class FilterCrop extends AbstractFilter {
    @XStreamAsAttribute
    @ParamAnnotation(name = "起始X坐标", desc = "起始X坐标",inputType = ParamAnnotation.InputType.Spinner)
    int x=1;
    @XStreamAsAttribute
    @ParamAnnotation(name = "起始Y坐标", desc = "起始Y坐标",inputType = ParamAnnotation.InputType.Spinner)
    int y=1;
    @XStreamAsAttribute
    @ParamAnnotation(name = "宽度", desc = "宽度",inputType = ParamAnnotation.InputType.Spinner)
    int width=32;
    @XStreamAsAttribute
    @ParamAnnotation(name = "高度", desc = "高度",inputType = ParamAnnotation.InputType.Spinner)
    int height=32;


    @Override
    public BufferedImageOp getFilter() {
        return new CropFilter(x,y,width,height);
    }

    @Override
    public BufferedImage filter(BufferedImage src, BufferedImage dst) {
        return getFilter().filter(src, null);
    }
}
